package wviz.index;

import java.util.HashMap;
import java.util.Map;

/**
 * Store stemmed version of a word with frequency information for the original
 * word forms
 * 
 * @author Laurie
 */
public class StemmingInformation {

	private static Map<String /* stemmedword */, Map<String /* original word */, Integer /* frequency */>> stemmed_original_freqMap = new HashMap<String, Map<String, Integer>>();

	public static void addWord(String stemmedWord, String originalForm) {
		Map<String, Integer> original_freqMap = stemmed_original_freqMap
				.get(stemmedWord);

		if (original_freqMap != null) { // i.e. already exists in the map
			Integer freq = original_freqMap.get(originalForm);
			if (freq == null)
				freq = 0;
			original_freqMap.put(originalForm, freq + 1);
		} else { // i.e. a new word
			original_freqMap = new HashMap<String /* original form */, Integer/* Frequency */>();
			original_freqMap.put(originalForm, 1);
			stemmed_original_freqMap.put(stemmedWord, original_freqMap);
		}
	}

	public static String getMostFrequentSurfaceForm(String stemmedWord) {

		Map<String, Integer> originalForm_freqMap = stemmed_original_freqMap
				.get(stemmedWord);

		int maxFreq = 0;
		String mostFrequentWordForm = new String ();
		for (String form : originalForm_freqMap.keySet()) {
			int freq = originalForm_freqMap.get(form);

 //System.out.println("stemminginginformation form " + form +
	//		 " freq " + freq);
			if (freq > maxFreq) {
				maxFreq = freq;
				mostFrequentWordForm = form;
			}
		}
//		if (mostFrequentWordForm.equalsIgnoreCase("concept"))
//			return "conceptual";
//		if (mostFrequentWordForm.equalsIgnoreCase("occurring")
//				|| mostFrequentWordForm.equalsIgnoreCase("occurrence"))
//			return "occurr";

		return mostFrequentWordForm;
	}
}